package dp;

public class dp1 {
    public static void main(String[] args) {


    }

    public int minCostClimbingStairs2(int[] cost) {
        int dp1=0;
        int dp2=0;
        int dp3=0;
        for(int i=2;i<=cost.length;i++){
            dp3=Math.min(dp1+cost[i-2],dp2+cost[i-1]);
            dp1=dp2;
            dp2=dp3;
        }
        return dp3;
    }

    public int minCostClimbingStairs(int[] cost) {
        int []dp=new int[cost.length+1];
        for(int i=2;i<=cost.length;i++){
            dp[i]=Math.min(dp[i-1]+cost[i-1],dp[i-2]+cost[i-2]);
        }
        return dp[cost.length];
    }


    public int waysToStep(int n) {
        int a=(int)1e9+7;
        int []dp=new int[n+3];
        dp[0]=0;
        dp[1]=0;
        dp[2]=1;
        for(int i=3;i<n+3;i++){
            dp[i]=((dp[i-1]+dp[i-2])%a+dp[i-3])%a;
        }
        return dp[n+2];
    }


    public int tribonacci(int n) {
        if(n==0)return 0;
        if(n==1||n==2)return 1;
        int[]dp=new int[n+1];
        dp[0]=0;dp[1]=1;dp[2]=1;
        for(int i=3;i<=n;i++){
            dp[i]=dp[i-3]+dp[i-2]+dp[i-1];
        }
        return dp[n];
    }

}
